package com.jolink.omiis.wechat;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import com.jolink.omiis.wechat.keys.IPreferences;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;

/**
 * 
 * 微信Server入口
 * @author WangYanqing
 *
 */
@SpringBootApplication
@ComponentScan(value="com.jolink.omiis")
public class OmiisWechatApplication {

	private static Logger logger = LoggerFactory.getLogger(OmiisWechatApplication.class);

	public static void main(String[] args) {
		long t1 = System.currentTimeMillis();
		logger.info("开始启动微信服务平台......");
		SpringApplication.run(OmiisWechatApplication.class, args);
		long t2 = System.currentTimeMillis();
		logger.info("微信服务平台启动完成，耗时：{}毫秒。", (t2 - t1));
	}

	static {
		File logbackFile = new File(IPreferences.LOG_BACK_CONFIG);
		if (logbackFile.exists()) {
			LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
			JoranConfigurator configurator = new JoranConfigurator();
			configurator.setContext(lc);
			lc.reset();
			try {
				configurator.doConfigure(logbackFile);
			} catch (JoranException e) {
				e.printStackTrace(System.err);
				System.exit(-1);
			}
		}
	}
}
